package com.docwei.thansgank;

import java.lang.ref.WeakReference;

/**
 * Created by tobo on 17/8/1.
 * T是type V是value
 */

public abstract class BasePresenter<T extends BaseView>  {
    public WeakReference<T> mViewReference;
    public BasePresenter(T view) {
        //将View添加到Presenter
        mViewReference=new WeakReference<T>(view);
    }
    public T getUiView(){
      return mViewReference.get();
    }
    public boolean isViewAtteched(){
        return mViewReference!=null&&mViewReference.get()!=null;
    }
    //将View从Presenter释放
    public void detachUiView(){
        if(mViewReference!=null){
            mViewReference.clear();
            mViewReference=null;
        }
    }
}
